<?php

use Faker\Factory as Faker;
use App\Models\GoodsContent;
use App\Repositories\GoodsContentRepository;

trait MakeGoodsContentTrait
{
    /**
     * Create fake instance of GoodsContent and save it in database
     *
     * @param array $goodsContentFields
     * @return GoodsContent
     */
    public function makeGoodsContent($goodsContentFields = [])
    {
        /** @var GoodsContentRepository $goodsContentRepo */
        $goodsContentRepo = App::make(GoodsContentRepository::class);
        $theme = $this->fakeGoodsContentData($goodsContentFields);
        return $goodsContentRepo->create($theme);
    }

    /**
     * Get fake instance of GoodsContent
     *
     * @param array $goodsContentFields
     * @return GoodsContent
     */
    public function fakeGoodsContent($goodsContentFields = [])
    {
        return new GoodsContent($this->fakeGoodsContentData($goodsContentFields));
    }

    /**
     * Get fake data of GoodsContent
     *
     * @param array $postFields
     * @return array
     */
    public function fakeGoodsContentData($goodsContentFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'goods_id' => $fake->randomDigitNotNull,
            'url' => $fake->text,
            'sort' => $fake->randomDigitNotNull,
            'created_at' => $fake->word,
            'updated_at' => $fake->word
        ], $goodsContentFields);
    }
}
